<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计算</title>
	</head>
	<body>
		<input type="text" name="" id="a" value="" />
		<select name="select1" id='s'>
			<option value="+">+</option>
			<option value="-">-</option>
			<option value="*">*</option>
			<option value="/">/</option>
		</select>
		<input type="text" name="" id="b" value="" />
		=
		<input type="text" name="" id="c" value="" />
		<button type="submit"  onclick="js()">确定</button>
	</body>
	<script type="text/javascript">
		function js(){
			var index=document.getElementById('s').selectedIndex;//获取select的索引值，通过getElementById的方式获取，用name没用
			var value=document.getElementById('s').options[index].value;//获取select选项的值
			var a1=document.getElementById('a').value;
			var b1=document.getElementById('b').value;
			var a=parseFloat(a1);
			var b=parseFloat(b1);
			
			switch (value){
				case '+':
				document.getElementById('c').value=a+b;
				console.log(document.getElementById('c').value)
					break;
				case '-':
				document.getElementById('c').value=a-b;
				console.log(document.getElementById('c').value)
					break;	
				case '*':
				document.getElementById('c').value=a*b;
				console.log(document.getElementById('c').value)
					break;	
				case '/':
				document.getElementById('c').value=a/b;
				console.log(document.getElementById('c').value)
					break;	
				default:
					break;
			}
				
			
		}

	</script>
</html>
